package com.xuqm.sdhbwfu.app.viewmodel

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.xuqm.base.di.manager.HttpManager
import com.xuqm.base.extensions.showMessage
import com.xuqm.sdhbwfu.app.model.InspectionListModel
import com.xuqm.sdhbwfu.app.repository.Service
import com.xuqm.sdhbwfu.core.extensions.io_main
import com.xuqm.sdhbwfu.core.extensions.subscribeBy
import com.xuqm.sdhbwfu.core.viewModel.BaseViewModel

class InspectionViewModel : BaseViewModel() {

    private val _list = MutableLiveData<List<InspectionListModel>>()
    val list: LiveData<List<InspectionListModel>> = _list
    private val _list1 = MutableLiveData<List<InspectionListModel>>()
    val list1: LiveData<List<InspectionListModel>> = _list1

    fun inspectionList() {
        HttpManager.getApi(Service::class.java)
            .inspectionList(0, 100, "notStarted")
            .io_main()
            .subscribeBy(
                {
                    _list.postValue(it)
                }, {
                    _list.postValue(null)
                    showMessage(it)
                }
            ).adds()
    }

    fun inspectionListing() {
        HttpManager.getApi(Service::class.java)
            .inspectionList(0, 100, "inspecting")
            .io_main()
            .subscribeBy(
                {
                    _list1.postValue(it)
                }, {
                    _list.postValue(null)
                    showMessage(it)
                }
            ).adds()
    }

    private val _getStatus = MutableLiveData<String>()
    val getStatus: LiveData<String> = _getStatus
    fun inspectionGet(id: Int) {
        HttpManager.getApi(Service::class.java)
            .inspectionGet(id)
            .io_main()
            .subscribeBy(
                {
                    _getStatus.postValue("success")
                }, {
                    _getStatus.postValue(null)
                    showMessage(it)
                }
            ).adds()
    }
}